package model;

import java.util.ArrayList;

import communication.Observer;
import communication.Subject;
import communication.TempData;

public class WheatherData implements Subject
{
	private float temperature;
	private float humidity;
	private float pressure;
	private ArrayList<Observer> obseverList;
	
	public WheatherData(int temperature, int humidity, int pressure) 
	{
		super();
		this.temperature = temperature;
		this.humidity = humidity;
		this.pressure = pressure;
		this.obseverList = new ArrayList<Observer>();
	}
	
	

	public void measurementsChanged() 
	{	
		this.notifyObservers();
	}

	public void setMesurements(float temperature, float humidity, float pressure)
	{
		this.temperature = temperature;
		this.humidity = humidity;
		this.pressure = pressure;
		measurementsChanged();
	}

	@Override
	public void notifyObservers() 
	{
		TempData tD = new TempData(temperature, humidity, pressure);
		for(int i=0; i< obseverList.size(); i++)
			obseverList.get(i).update(tD);
	}

	@Override
	public void addObserver(Observer observer) 
	{
		this.obseverList.add(observer);
	}

	@Override
	public void removeObserver(Observer observer) 
	{
		this.obseverList.remove(observer);
		
	}
}
